import { useModel } from "umi";
import { useReactive } from "ahooks";
import { useEffect } from "react";

const useAllCategory = () => {
    const { remoteData } = useModel("global");

    const state = useReactive({
        loading: false,
        categories: [],
    });

    const loadCategories = async () => {
        state.loading = true;
        let res = await remoteData({
            object: "bnt-application-resource-center-service",
            serviceName: "/developer/application/getOrganizationCategories",
            params: {
                order: [["acName", "ASC"]],
            },
        });
        state.categories = res || [];
        state.loading = false;
    };

    useEffect(() => {
        loadCategories();
    }, []);

    return { ...state, loadCategories };
};

export default useAllCategory;
